Command line arguments
Manual     Reference     Scripting   
Unity Manual > Advanced > Command line arguments

Command line arguments

It is possible to start the Unity Editor with command line arguments to make it run certain tasks upon opening. This allows automated game builds, test suites and so on. See below.

Additionally, standalone games built with Unity accept some command line parameters as well, see below.

Unity Editor command line arguments

-batchmode

Run Unity in batch mode. This should always be used in conjunction with the other command line arguments as it ensures no pop up windows appear and eliminates the need for any human intervention. When an exception occurs during execution of script code, asset server updates fail or other operations fail Unity will immediately exit with return code 1.

Note that in batch mode, Unity will write a stripped version of it's log output to the console. For full debug information, look at Unity's Log Files.

-quit

Quit Unity cleanly upon finishing execution of other command line arguments.

-buildWindowsPlayer

Build a standalone Windows player (eg, -buildWindowsPlayer path/to/your/build.exe).

-buildOSXPlayer

Build a standalone Mac OSX player (eg, -buildOSXPlayer path/to/your/build.app).

-importPackage packagepath

Import the given package. No import dialog is shown.

-createProject pathname

Create an empty project at the given path.

-projectPath pathname

Open the project at the given path.

-assetServerUpdate IP[:port] projectName username password [r <revision>]

Force an update of the project in the Asset Server given by IP:port. The port is optional and if not given it is assumed to be the standard one (10733). It is advisable to use this command in conjunction with the -projectPath argument to ensure you are working with the correct project. In no project name is given then the last project opened by Unity is used. If no project exists at the path given by -projectPath then one is created automatically.

-executeMethod ClassName.MethodName

Execute the static method as soon as Unity is started and the project folder has been opened and after the optional asset server update has been performed. This can be used to do continous integration: perform Unit Tests, make builds, prepare some data. If you want to return an error from the commandline process you can either throw an exception which will cause Unity to exit with 1. Or call EditorApplication.Exit with a non-zero code.

To use -executeMethod you need to have a script in an Editor folder and a static function in the class.

// C# example
using UnityEditor;
class MyEditorScript
{
     static void PerformBuild ()
     {
         string[] scenes = { "Assets/MyScene.unity" };
         BuildPipeline.BuildPlayer(scenes, ...);
     }
}
// JavaScript example
static void PerformBuild ()
{
    string[] scenes = { "Assets/MyScene.unity" };
    BuildPipeline.BuildPlayer(scenes, ...);
}

-exportPackage

Exports a package given a path. Usage: -exportPackage exportAssetPath exportFileName
Where: exportAssetPath: is the folder to export in the unity project
exportFileName: is the package name
Currently it only supports exporting only whole folders.

-nographics (Windows only)

When running in batch mode, do not initialize graphics device at all. This makes it possible to run your automated workflows on machines that don't even have a GPU.

Example usage

Execute Unity in batch mode, execute MyEditorScript.MyMethod method, and quit upon completion.

Windows:
C:\program files\Unity\Editor>Unity.exe -quit -batchmode -executeMethod MyEditorScript.MyMethod

Mac OS:
/Applications/Unity/Unity.app/Contents/MacOS/Unity -quit -batchmode -executeMethod MyEditorScript.MyMethod

Execute Unity in batch mode. Use the project path given and update from the asset server. Execute the given method after all assets have been downloaded and imported from the asset server. After the method has finished execution, automatically quit Unity.

/Applications/Unity/Unity.app/Contents/MacOS/Unity -batchmode -projectPath ~/UnityProjects/AutobuildProject -assetServerUpdate 192.168.1.1 MyGame AutobuildUser l33tpa33 -executeMethod MyEditorScript.PerformBuild -quit

Unity Standalone Player command line arguments

Standalone players built with Unity also understand some command line arguments:

-batchmode

Run the game in "headless" mode. The game will not display anything and won't accept user input. This is mostly useful for running servers of networked games.

-force-opengl (Windows only)

Make the game use OpenGL for rendering, even if Direct3D is availabe. Normally Direct3D is used; and OpenGL is used only if Direct3D 9.0c is not available.

-single-instance (Windows only)

Allow only one instance of the game to run at the time. If another game is already running, then launching it again with -single-instance will focus the existing one.

-nolog (Windows only)

Do not produce output log. Normally output_log.txt is written in the *_Data folder next to the game executable, where Debug.Log output is printed.

-force-d3d9-ref (Windows only)

Make the game run using Direct3D's "Reference" software renderer. DirectX SDK has to be installed for this to work. This is mostly useful for building automated test suites, where you want to ensure rendering is exactly the same no matter what's the graphics card.

-adapterN (Windows only)

Allows the game to run full-screen on another display, where N denotes the display number.

-popupwindow (Windows only)

The window will be created as a a pop-up window (without a frame).

Page last updated: 2011-07-11